package com.bite.system.manager;


import com.bit.common.redis.service.RedisService;
import com.bite.common.core.constants.CacheConstants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class QuestionCacheManager {

    @Autowired
    private RedisService redisService;

    public void addQuestion(Long questionId) {
        redisService.leftPushForList(getQuestionListKey(), questionId);
    }

    public void deleteQuestion(Long questionId) {
        redisService.removeForList(getQuestionListKey(), questionId);
    }

    private String getQuestionListKey() {
        return getQuestionListKey(null);
    }

    /**
     * 有竞赛那么就获取竞赛中题目列表的key 没有的话就获取所有的题目列表的key
     * @param examId
     * @return
     */
    private String getQuestionListKey(Long examId) {
        return examId == null ? CacheConstants.QUESTION_LIST : CacheConstants.EXAM_QUESTION_LIST + examId;
    }
}
